package Send2ME::Dao::Auth;

use Send2ME::Dao::User;

use Exporter 'import';
@EXPORT = qw(credential currentUser isLoggedIn logout);

use Dancer ':syntax';
use Dancer::Plugin::Database;

sub currentUser {
	if ($_[0]) { #set
		session->destroy();
		session current_user => $_[0];
	} else { #get
		return session('current_user');
	} 
}

sub isLoggedIn {
	return defined currentUser();
}

sub logout {
	session->destroy();
}

sub credential {
	return {
		logged_in => isLoggedIn(),
		user => currentUser()
	};
}

1;